import {takeEvery, select, call, put, take} from 'redux-saga/effects'
import axios from 'axios'

// 引入状态和常量
import { DOREGISTERSAGA, GETCAPTCHASAGA, DOREGISTERVALUE } from '../constants'
import { DoRegisterValue } from '../actions/register'
import { API_URL, API_URL_GO } from '../../env'


// 向后端发送注册信息
function* doRegisterSaga(action) {
    const res = yield call(axios.post, API_URL_GO + "register/do", {...action.data})
    console.log("注册提交, 返回的数据为: ", res)
    yield put(DoRegisterValue(res.data.message))

}

// 向后端发送获取验证码
function* getCaptchaSaga(action) {
    const res = yield call(axios.post, API_URL_GO + "register/captcha", {...action.data})
}
export function* registerSaga () {
    yield takeEvery(DOREGISTERSAGA, doRegisterSaga)
    yield takeEvery(GETCAPTCHASAGA, getCaptchaSaga)
}